<template>
  <div class="picture">
    <h3>我是Picture组件，一共有{{personList.length}}人在看图片</h3>
    <button @click="handleGetImg">获取一张随机的图片</button><br><br>
    <img :src="img.url" v-for="img in imgList" :key="img.id">
  </div>
</template>

<script>
import { mapState } from 'vuex'
  export default {
    name:'Picture',
    computed:{
      ...mapState(['imgList','personList'])
    },
    methods: {
      handleGetImg(){
        this.$store.dispatch('getGoodImg')
      }
    },
  }
</script>

<style scoped>
  .picture {
    background-color: skyblue;
    padding: 10px;
    box-shadow: 0 0 10px;
    border-radius: 10px;
  }
  img {
    height: 100px;
    margin-right: 10px;
  }
</style>